﻿using BasicInformation.API.Application.Command.OwnerCommand;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.OwnerCommandHandler
{
    public class OwnerBatchDeleteCommandHandler : IRequestHandler<OwnerBatchDeleteCommand, int>
    {
        private readonly IOwnerRepository ownerRepository;

        public OwnerBatchDeleteCommandHandler(IOwnerRepository ownerRepository)
        {
            this.ownerRepository = ownerRepository;
        }
        public async Task<int> Handle(OwnerBatchDeleteCommand request, CancellationToken cancellationToken)
        {
            var Id = request.Ids.Split(',').Select(int.Parse).ToArray();
            var list = await ownerRepository.GetListInfo(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await ownerRepository.UpdateRange(list);
        }
    }
}
